package com.webserver.core;

import com.webserver.controllers.UserController;
import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class DispatcherServlet {
    public void service(HttpRequest request, HttpResponse response){
        String path =request.getRequestURI();
        if ("/myweb/regUser".equals(path)){
            UserController controller =new UserController();
            controller.reg(request,response);
        }else {
            File file = new File("./webapps" + path);
            if (file.exists() && file.isFile()) {
                response.setEntity(file);


            } else {
                response.setStatusCode(404);
                response.setStatusReason("NotFound");
                file = new File("./webapps/root/404.html");
                response.setEntity(file);
            }
        }
        response.addHeader("Server","WebServer");
    }
}
